<template>
  <div>
    <el-button type="primary" @click="handleAdd">新增角色</el-button>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column label="角色ID">
        <template #default="scope">
          {{ scope.row.objectId }}
        </template>
      </el-table-column>
      <el-table-column label="角色名称">
        <template #default="scope">
          {{ scope.row.roleName }}
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-drawer v-model="drawer" title="录入角色">
      <RoleForm v-if="drawer" @trans-role-data="addRole" :idx="editIdx" :row="rowData" />
    </el-drawer>
  </div>
</template>

<script>
import { roleGet } from '../../api/user';
import RoleForm from './components/role-form.vue'
export default {
  components: {
    RoleForm
  },
  data() {
    return {
      tableData: [],
      drawer: false,
      editIdx: -1,
      rowData: null,
    }
  },
  created() {
    roleGet().then(res => {
      this.tableData = res.data.results
    })
  },
  methods: {
    handleAdd() {
      this.drawer = true
    },
    handleEdit() {

    },
    handleDelete() {

    },
    addRole(obj) {
      this.tableData.push(obj)
    }
  }
}
</script>

<style lang="scss" scoped>

</style>